REBOL [
	Title: "RebGUI Documentation"
	Owner: "Ashley G Truter"
	Purpose: "Documents & demonstrates RebGUI widgets, requestors and functions."
]

do %rebgui.r

make object! [

	widgets: sort find first ctx-rebgui/widgets 'anim
	keywords: exclude ctx-rebgui/words widgets
	requestors: find first ctx-rebgui/requestors 'alert
	functions: find first ctx-rebgui/functions 'clear-text
	objects: copy [ctx-rebgui/widgets/baseface ctx-rebgui/widgets/gradface ctx-rebgui/behaviors ctx-rebgui/colors ctx-rebgui/edit ctx-rebgui/effects ctx-rebgui/locale* ctx-rebgui/on-error ctx-rebgui/on-fkey ctx-rebgui/sizes]

	keyword-text: find mold get 'layout "'return"
	clear find keyword-text "| [set arg integer!"
	replace/all keyword-text "| '" "& '"
	replace/all keyword-text "  " " "

	sizes: make object! [
		view: to integer! (length? mold/only get ctx-rebgui/view*) / 1024
		locale: to integer! (length? mold/only get ctx-rebgui/locale*) / 1024
		rebgui: to integer! (length? mold/only get ctx-rebgui) / 1024 - view - locale
		widgets: to integer! (length? mold/only get ctx-rebgui/widgets) / 1024
		keywords: to integer! (length? mold/only get 'layout) / 1024
		requestors: to integer! (length? mold/only get ctx-rebgui/requestors) / 1024
		functions: to integer! (length? mold/only get ctx-rebgui/functions) / 1024
		objects: rebgui - widgets - requestors - functions
	]

	func-help: make function! ['word /local s p1 p2] [
		p1: :print
		p2: :prin
		s: make string! 4096
		print: make function! [data] [insert tail s form reduce data insert tail s "^/"]
		prin: make function! [data] [insert tail s form reduce data]
		help :word
		print: :p1
		prin: :p2
		trim/tail s
	]

	show-ref: make function! [word face /widget /keyword /requestor /object /local txt lnk lay arg] [
		unless keyword [
			all [word? word word: to word! word]
			txt: either widget [examine/no-print :word] [func-help :word]
		]
		lnk: case [
			widget [https://rebgui.svn.codeplex.com/svn/widgets/]
			keyword [https://rebgui.svn.codeplex.com/svn/functions/layout.r]
			requestor [https://rebgui.svn.codeplex.com/svn/requestors/]
			object [https://rebgui.svn.codeplex.com/svn/]
			true [https://rebgui.svn.codeplex.com/svn/functions/]
		]
		if requestor [
			arg: switch/default word [
				flash [["Message" wait 2 hide-popup wait []]]
				request-about [["RebGUI" 2.0.0 "Copyright (c) 2009 Dobeash Software"]]
				request-list [[["Item 1" "Item 2" "Item 3"]]]
				request-menu [[face ["A" [] "B" [] "C" []]]]
				request-progress [[10 [loop 10 [wait .5 step]]]]
				request-spellcheck [[make ctx-rebgui/widgets/baseface [text: "wordz"]]]
				request-verify [[["L1" "L2"] [v1 v2]]]
				splash [[%icons/Tango-feet.png unview]]
			] [
				copy "Text."
			]
		]
		lay: either keyword [
			trim/tail txt: skip first parse/all find keyword-text join "'" word "&" 2 + length? form word
			compose/deep [
				after 1
				heading (form word)
			]
		] [
			compose/deep [
				after 1
				heading (either object [form word] [uppercase/part form word 1])
				panel 150 data [
					after 2
					label 20 "Source" link (rejoin [lnk either object [%rebgui-ctx] [word] %.r])
					label 20 "Size" text (remove reform [to money! (length? mold/only get either widget [ctx-rebgui/widgets/:word] [either word? word [word] [do word]]) / 1024 "Kb"])
				]
			]
		]
		all [
			widget
			insert tail lay compose/deep [panel 150 data [(load trim second parse/all txt "^/")]]
			all [
				find [drop-list edit-list menu] word
				insert tail last lay 'return
				insert tail last lay 'text
			]
		]
		all [
			requestor
			insert tail lay compose/deep [panel 150 data [button 45x15 (form word) [(word) (arg)]]]
		]
		insert tail lay [panel 150 data [text txt font [name: "Courier"]]]
		lay: layout/only lay
		face/pane/1/pane: lay
		face/pane/1/size: lay/size
		face/action/on-resize face
		if scroll/picked = 2 [face/pane/2/data: 0]
		show face
	]

	scroll: none

	do show-tour: make function! [] [
		display "RebGUI Documentation" [
			;			image %images/logo.png
			return
			tab-panel data [
				"Widgets" [
					text-list 40x112 data widgets [
						show-ref/widget face/selected first in-widget face/parent-face/parent-face 'scroll-panel
					]
					scroll-panel 162x112 options [offset] data [
						after 1
						heading "Widgets"
						panel 150 data [
							after 2
							label 20 "Source" link https://rebgui.svn.codeplex.com/svn/rebgui-widgets.r
							label 20 "Size" text (reform [sizes/widgets "Kb"])
							label 20 "Number" text (form length? widgets)
						]
						panel 150 data [
							text (func-help ctx-rebgui/widgets) font [name: "Courier"]
						]
					]
				]
				"Keywords" [
					text-list 40x112 data keywords [
						show-ref/keyword face/selected first in-widget face/parent-face/parent-face 'scroll-panel
					]
					scroll-panel 162x112 options [offset] data [
						after 1
						heading "Keywords"
						panel 150 data [
							after 2
							label 20 "Source" link https://rebgui.svn.codeplex.com/svn/functions/layout.r
							label 20 "Size" text (reform [sizes/keywords "Kb"])
							label 20 "Number" text (form length? keywords)
						]
					]
				]
				"Requestors" [
					text-list 40x112 data requestors [
						show-ref/requestor face/selected first in-widget face/parent-face/parent-face 'scroll-panel
					]
					scroll-panel 162x112 options [offset] data [
						after 1
						heading "Requestors"
						panel 150 data [
							after 2
							label 20 "Source" link https://rebgui.svn.codeplex.com/svn/rebgui-requestors.r
							label 20 "Size" text (reform [sizes/requestors "Kb"])
							label 20 "Number" text (form length? requestors)
						]
						panel 150 data [
							text (func-help ctx-rebgui/requestors) font [name: "Courier"]
						]
					]
				]
				"Functions" [
					text-list 40x112 data functions [
						show-ref face/selected first in-widget face/parent-face/parent-face 'scroll-panel
					]
					scroll-panel 162x112 options [offset] data [
						after 1
						heading "Functions"
						panel 150 data [
							after 2
							label 20 "Source" link https://rebgui.svn.codeplex.com/svn/rebgui-functions.r
							label 20 "Size" text (reform [sizes/functions "Kb"])
							label 20 "Number" text (form length? functions)
						]
						panel 150 data [
							text (func-help ctx-rebgui/functions) font [name: "Courier"]
						]
					]
				]
				"Objects" [
					text-list 40x112 data objects [
						show-ref/object face/selected first in-widget face/parent-face/parent-face 'scroll-panel
					]
					scroll-panel 162x112 options [offset] data [
						after 1
						heading "Objects"
						panel 150 data [
							after 2
							label 20 "Source" link https://rebgui.svn.codeplex.com/svn/rebgui-ctx.r
							label 20 "Size" text (reform [sizes/objects "Kb"])
							label 20 "Number" text (form length? objects)
						]
						panel 150 data [
							text (func-help ctx-rebgui) font [name: "Courier"]
						]
					]
				]
				"Colors" [
					panel snow data [
						after 3
						label "page" box 10x10 ctx-rebgui/colors/page text "Main background/Reversed text"
						label "text" box 10x10 ctx-rebgui/colors/text text "Normal text"
						label "true" box 10x10 ctx-rebgui/colors/true text "Radio/Check/LED color"
						label "false" box 10x10 ctx-rebgui/colors/false text "LED color"
						label "link" box 10x10 ctx-rebgui/colors/link text "Link text"
					]
					panel snow data [
						after 3
						label "theme/1" box 10x10 ctx-rebgui/colors/theme/1 text "Theme light"
						label "theme/2" box 10x10 ctx-rebgui/colors/theme/2 text "Theme normal"
						label "theme/3" box 10x10 ctx-rebgui/colors/theme/3 text "Theme dark"
						label "outline/1" box 10x10 ctx-rebgui/colors/outline/1 text "Outline light"
						label "outline/2" box 10x10 ctx-rebgui/colors/outline/2 text "Outline normal"
						label "outline/3" box 10x10 ctx-rebgui/colors/outline/3 text "Outline dark"
					]
				]
			]
			return
			bar
			reverse
			button "Close" [quit]
			button "Stats" [
				request-verify/ok ["Widgets" "Requestors" "Functions" "Objects"] reduce [
					join sizes/widgets "Kb"
					join sizes/requestors "Kb"
					join sizes/functions "Kb"
					join sizes/objects "Kb"
				]
			]
			scroll: radio-group 30x5 data [1 "Sticky" "Reset"]
			label "Scroll:"
		]
	]
]

do-events